<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="/public/css/login.css">
</head>

<body>
	<div class="main">
		<div class="header">
			<a href="/">
				<img src="/public/img/logo3.png" alt="">
			</a>
			<h1>用户登录</h1>
		</div>
		<form id="login_form" action="/login" method="post">
			<div class="form-group">
				<label for="">邮箱</label>
				<input type="email" class="form-control" id="" name="email" placeholder="Email" autofocus>
			</div>
			<div class="form-group">
				<label for="">密码</label>
				<a class="pull-right" href="">忘记密码？</a>
				<input type="password" class="form-control" id="" name="password" placeholder="Password">
			</div>
			<div class="checkbox">
				<label>
					<input type="checkbox">记住我
				</label>
			</div>
			<button type="submit" class="btn btn-success btn-block">登录</button>
		</form>
		<div class="message">
			<p>没有账号? <a href="/register">点击创建</a>.</p>
		</div>
	</div>
	
</body>
<script src="/public/js/jquery.js"></script>
<script >
	$('#login_form').on('submit',function(e){
		e.preventDefault()
		var formData=$(this).serialize()
		console.log(formData)
		$.ajax({
			url:'/login',
			type:'post',
			data:formData,
			dataType:'json',
			success:function(data){
				var code=data.code
				console.log(code)
				if(code===0){
					window.location.href='/'
				}else if(code===1){
					alert('用户名或密码错误')
				}else if(code===500){
					alert('服务端错误')
				}
			}
		})
	})
</script>

</html>
